using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class AcctMatchingMap : EntityTypeConfiguration<AcctMatching>
    {
        public AcctMatchingMap()
        {
            // Primary Key
            this.HasKey(t => new { t.ID, t.COMPACCT, t.SUBCOMPACCT, t.SUBDATABASE });

            // Properties
            this.Property(t => t.ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.COMPACCT)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.SUBCOMPACCT)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.SUBDATABASE)
                .IsRequired()
                .HasMaxLength(120);

            // Table & Column Mappings
            this.ToTable("AcctMatching");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.COMPACCT).HasColumnName("COMPACCT");
            this.Property(t => t.SUBCOMPACCT).HasColumnName("SUBCOMPACCT");
            this.Property(t => t.SUBDATABASE).HasColumnName("SUBDATABASE");

            // Relationships
            this.HasRequired(t => t.Acct)
                .WithMany(t => t.AcctMatchings)
                .HasForeignKey(d => d.COMPACCT);

        }
    }
}
